/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JEventPanel.java
 *
 * Created on 2010-maj-19, 14:38:30
 */

package foalvleditor.gui;

import foalvleditor.core.impl.LevelModel;
import foalvleditor.gameobjects.GameEvent;
import org.jdesktop.application.Action;


/**
 *
 * @author fish
 */
public class JEventPanel extends javax.swing.JPanel {

    /**
	 *
	 */
	private static final long serialVersionUID = 1L;
	private GameEvent event;
    private static LevelModel levelModel=LevelModel.getInstance();

    /** Creates new form JEventPanel */
    public JEventPanel(GameEvent event) {
        super();
        initComponents();
        setEvent(event);
    }

    public final void setEvent(GameEvent event){
        this.event=event;
        if (event!=null){
            jLabel1.setText(event.getType().displayableName);
            JSimpleObjectPanel newEventPanel;
            for (int i=0; i<event.getObjectList().size(); i++)
            {
                newEventPanel=new JSimpleObjectPanel(event.getObjectList().get(i));
                jPanel1.add(newEventPanel);
            }
            firstObjectPanel.setObject(event.getFirstObject());
        this.repaint();
        }
    }

    public GameEvent getEvent(){
        return this.event;
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        deleteButton = new javax.swing.JButton();
        deleteButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        firstObjectPanel = new foalvleditor.gui.JSimpleObjectPanel();

        setMaximumSize(new java.awt.Dimension(340, 100));
        setMinimumSize(new java.awt.Dimension(340, 100));
        setName("Form"); // NOI18N
        setPreferredSize(new java.awt.Dimension(340, 100));

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N
        jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.LINE_AXIS));
        jScrollPane1.setViewportView(jPanel1);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(foalvleditor.core.FoaLvlEditorApp.class).getContext().getActionMap(JEventPanel.class, this);
        deleteButton.setAction(actionMap.get("deleteObject")); // NOI18N
        deleteButton.setBorderPainted(false);
        deleteButton.setContentAreaFilled(false);
        deleteButton.setFocusPainted(false);
        deleteButton.setMaximumSize(new java.awt.Dimension(35, 35));
        deleteButton.setMinimumSize(new java.awt.Dimension(35, 35));
        deleteButton.setName("deleteButton"); // NOI18N
        deleteButton.setPreferredSize(new java.awt.Dimension(35, 35));

        deleteButton1.setAction(actionMap.get("deleteEvent")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(foalvleditor.core.FoaLvlEditorApp.class).getContext().getResourceMap(JEventPanel.class);
        deleteButton1.setIcon(resourceMap.getIcon("deleteButton1.icon")); // NOI18N
        deleteButton1.setBorderPainted(false);
        deleteButton1.setContentAreaFilled(false);
        deleteButton1.setFocusPainted(false);
        deleteButton1.setMaximumSize(new java.awt.Dimension(35, 35));
        deleteButton1.setMinimumSize(new java.awt.Dimension(35, 35));
        deleteButton1.setName("deleteButton1"); // NOI18N
        deleteButton1.setPreferredSize(new java.awt.Dimension(35, 35));
        deleteButton1.setPressedIcon(resourceMap.getIcon("deleteButton1.pressedIcon")); // NOI18N
        deleteButton1.setRolloverIcon(resourceMap.getIcon("deleteButton1.rolloverIcon")); // NOI18N

        jLabel1.setFont(resourceMap.getFont("jLabel1.font")); // NOI18N
        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setFont(resourceMap.getFont("jLabel2.font")); // NOI18N
        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        firstObjectPanel.setName("firstObjectPanel"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(firstObjectPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 205, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(deleteButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(168, 168, 168)
                    .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(141, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(deleteButton1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(firstObjectPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 73, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(31, 31, 31)
                    .addComponent(deleteButton, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(34, Short.MAX_VALUE)))
        );
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void deleteEvent() {
        levelModel.removeEvent(this.event);
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton deleteButton;
    private javax.swing.JButton deleteButton1;
    private foalvleditor.gui.JSimpleObjectPanel firstObjectPanel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
